import { Component, OnInit, ViewChild, ContentChild, AfterViewInit, ElementRef } from '@angular/core';
import { ElectronService } from './providers/electron.service';
import { TranslateService } from '@ngx-translate/core';
import { AppConfig } from '../environments/environment';
import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  @ViewChild(RouterOutlet) routerOutlet: RouterOutlet;
  showBorder: boolean;
  href: string;
  constructor(public electronService: ElectronService,
    // private translate: TranslateService,
    private el: ElementRef) {
      this.el.nativeElement.ngComponent = this;
      // translate.setDefaultLang('zh-cn');
      console.log('AppConfig', AppConfig);

      if (electronService.isElectron()) {
        console.log('Mode electron');
        // console.log('Electron ipcRenderer', electronService.ipcRenderer);
        // console.log('NodeJS childProcess', electronService.childProcess);
      } else {
        console.log('Mode web');
      }
  }
  getTitle(): string {
    const title = this.electronService.getCurrentWindowTitle();
    return title || '默认标题';
  }
  ngOnInit() {
    const nativeDocument = this.el.nativeElement.ownerDocument;
    // nativeDocument.getElementById('title').innerHTML = this.getTitle();
    // this.routerOutlet.activateEvents.subscribe(evt => {
    //   const activatedRoute = this.routerOutlet.activatedRoute;
    //   const snapshot = activatedRoute.snapshot;
    //   let href: string;
    //   let params: string;
    //   href = '/' + snapshot.url.join('/');
    //   if (snapshot.queryParamMap.keys.length > 0) {
    //     params = '';
    //     snapshot.queryParamMap.keys.forEach(key => {
    //       params += `${key}=${snapshot.queryParamMap.get(key)}`;
    //     });
    //   }
    //   href += params ? '?' + params : '';
    //   const showBorder = snapshot.queryParamMap.get('showborder');
    //   this.showBorder = showBorder === '1';
    //   this.href = href;
    // });
  }
  openDevTools() {
    this.electronService.openDevTools();
  }
  closeDevTools() {
    this.electronService.closeDevTools();
  }
}
